package com.czh.controller;

import com.czh.domain.ResponseResult;
import com.czh.domain.dto.QueryLinkDto;
import com.czh.domain.entity.Link;
import com.czh.domain.vo.LinkPageVo;
import com.czh.domain.vo.LinkShowVo;
import com.czh.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * 友链管理
 */
@RestController
@RequestMapping("/content/link")
public class LinkManageController {
    @Resource
    private LinkService linkService;
    // 展示友链列表
    @GetMapping("/list")
    public ResponseResult<LinkPageVo> pageLink(Integer pageNum, Integer pageSize, QueryLinkDto queryLinkDto) {
        return linkService.pageLink(pageNum ,pageSize, queryLinkDto);
    }
    // 添加友链
    @PostMapping
    public ResponseResult<Object> addLink(@RequestBody Link link) {
        return linkService.addLink(link);
    }
    // 修改友链填充信息
    @GetMapping("/{id}")
    public ResponseResult<LinkShowVo> getLinkById(@PathVariable Long id) {
        return linkService.getLinkById(id);
    }
    // 修改友链
    @PutMapping
    public ResponseResult<Object> updateLink(@RequestBody Link link) {
        return linkService.updateLink(link);
    }
    // 删除友链
    @DeleteMapping("/{id}")
    public ResponseResult<Object> deleteLink(@PathVariable Long id) {
        return linkService.deleteLink(id);
    }
}
